package model;

import com.google.gson.annotations.Expose;

import java.util.Date;
import java.util.Objects;

public class Order {
    @Expose
    private String orderId;

    @Expose
    private Date orderDate;

    @Expose
    private double totalAmount;

    private String customerId;  // 默认不标注 @Expose，则不会被序列化

    public Order(String orderId, Date orderDate, double totalAmount, String customerId) {
        this.orderId = orderId;
        this.orderDate = orderDate;
        this.totalAmount = totalAmount;
        this.customerId = customerId;
    }

    // Getters and Setters
    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId='" + orderId + '\'' +
                ", orderDate=" + orderDate +
                ", totalAmount=" + totalAmount +
                ", customerId='" + customerId + '\'' +
                '}';
    }

    // 重写 equals 方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Order order = (Order) o;
        return Double.compare(order.totalAmount, totalAmount) == 0 &&
                Objects.equals(orderId, order.orderId) &&
                Objects.equals(orderDate, order.orderDate) &&
                Objects.equals(customerId, order.customerId);
    }

    // 重写 hashCode 方法
    @Override
    public int hashCode() {
        return Objects.hash(orderId, orderDate, totalAmount, customerId);
    }
}
